<template>
    <div class="screenFull">
      <div v-show="!isFullscreen" @click="handleFullScreen">
        <el-popover placement="top-start" trigger="hover" content="全屏显示">
          <font-awesome-icon :icon="['fas', 'expand-arrows-alt']" slot="reference" size="2x"></font-awesome-icon>
        </el-popover>
      </div>
      <div v-show="isFullscreen" @click="handleFullScreen">
        <el-popover placement="top-start" trigger="hover" content="退出全屏">
          <font-awesome-icon :icon="['fas', 'expand-arrows-alt']" slot="reference" size="2x"></font-awesome-icon>
        </el-popover>
      </div>
    </div>
</template>

<script>
import screenfull from "screenfull";  //引入依赖
export default {
  name: "screenFull",

  data() {
    return {
      isFullscreen: false, //是否全屏

    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    handleFullScreen() {
      if (!screenfull.isEnabled) {
        this.$message.info("您的浏览器版本过低，不支持全屏浏览");
        return false;
      }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off("change", this.change);
      }
    },
  },
}
</script>

<style scoped>

</style>
